package com.fau.om.action.index;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fau.om.action.PublicAction;
import com.fau.om.entity.MedicalCallCustomer;
import com.fau.om.entity.MedicalOrdersPass;
import com.fau.om.entity.MedicalOrdersStorage;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 订单维护Action
 * @author kangyj
 * @datetime 2014年11月27日,下午1:24:42
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class MaintainAction extends PublicAction implements ModelDriven<MedicalOrdersPass> {

	private static final long serialVersionUID = -9182517997847096190L;
	
	private MedicalOrdersPass ordersPass = new MedicalOrdersPass();
	
	/**
	 * @desc 订单详细tabs页初始化
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午1:25:39
	 */
	@Action(value = "maintain_orders_detail_init", results = {@Result(name = SUCCESS, location = "maintain_orders_detail_init.jsp")})
	public String ordersDetailInit() {
		return SUCCESS;
	}
	
	/**
	 * @desc 订单详细tab页
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午1:29:33
	 */
	@Action(value = "maintain_orders_detail_tab", results = {@Result(name = SUCCESS, location = "maintain_orders_detail_tab.jsp")})
	public String ordersDetailTab() {
		return SUCCESS;
	}
	
	/**
	 * @desc 客户详细tab页
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午1:31:05
	 */
	@Action(value = "maintain_customer_detail_tab", results = {@Result(name = SUCCESS, location = "maintain_customer_detail_tab.jsp")})
	public String customerDetailTab() {
		return SUCCESS;
	}
	
	/**
	 * @desc 根据订单id查询订单产品
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午1:47:21
	 */
	@Action(value = "maintain_orders_find_product")
	public String findProductList() {
		HttpServletResponse response = ServletActionContext.getResponse();
		list = this.baseAllService.getMaintainManagerService().findProductByOid(ordersPass.getId());
		formatJSON(response, list);
		return null;
	}
	
	/**
	 * @desc 根据id查询订单
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午1:52:38
	 */
	@Action(value = "maintain_orders_detail_view")
	public String ordersDetailView() {
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		MedicalOrdersStorage ordersStorage = this.baseAllService.getMaintainManagerService().findOrdersStorageById(ordersPass.getId());
		map.put("ordersStorage", ordersStorage);
		formatJSON(response, map);
		return null;
	}
	
	/**
	 * @desc 通过id查询客户
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月27日,下午2:00:26
	 */
	@Action(value = "maintain_customer_detail_view")
	public String customerDetailView() {
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		MedicalCallCustomer customer = this.baseAllService.getMaintainManagerService().findCustomerById(ordersPass.getCustomerId());
		map.put("customer", customer);
		formatJSON(response, map);
		return null;
	}
	
	@Override
	public MedicalOrdersPass getModel() {
		return ordersPass;
	}

}
